package A1_单调栈;

import java.util.Stack;

public class LC_739每日温度 {
    public static void main(String[] args){
        int[] temperatures = {73,74,75,71,69,72,76,73};
        int[] res=dailyTemperatures(temperatures);
        System.out.println(res);
    }
    public static int[] dailyTemperatures(int[] temperatures) {
        Stack<Integer> st=new Stack<Integer>();
        int[] result=new int[temperatures.length];
        st.push(0);
        for(int i=1;i<temperatures.length;i++){
            if(temperatures[i]<=temperatures[st.peek()])
                st.push(i);
            else {
                while(!st.isEmpty() && temperatures[i]>temperatures[st.peek()]){
                    result[st.peek()]=i-st.peek();
                    st.pop();
                }
            }
            st.push(i);
        }
        return result;

    }
}
